import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../../../data/models/bt_friend.dart';
import '../models/bt_followed_list_model.dart';

class BtFollowedItemWidget extends StatelessWidget {
  const BtFollowedItemWidget({super.key, required this.index, required this.item, required this.model});

  final int index;
  final BtFriend item;
  final BtFollowedListModel model;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(left: 18, top: 16, right: 20, bottom: 16),
      child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
        ClipRRect(
          borderRadius: BorderRadius.circular(22),
          child: CachedNetworkImage(
            width: 44,
            height: 44,
            fit: BoxFit.cover,
            imageUrl: item.avatarUrl,
          ),
        ),
        Expanded(
            child: Padding(
          padding: const EdgeInsets.only(left: 8),
          child: Text(
            item.nickname,
            style: const TextStyle(fontSize: 14, color: Color(0xFF202020), fontWeight: FontWeight.normal),
          ),
        )),
        InkWell(
          child: Container(
            width: 69,
            height: 28,
            padding: const EdgeInsets.only(top: 5),
            decoration: BoxDecoration(
              color: const Color(0xFFCCCCCC),
              borderRadius: BorderRadius.circular(32),
            ),
            child: const Text('Followed',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 12, color: Color(0xFFFFFFFF), fontWeight: FontWeight.normal)),
          ),
          onTap: () async {
            EasyLoading.show(status: 'Loading...');
            model.unfriend(item.userId, (success, msg) {
              EasyLoading.showToast(msg);
            });
          },
        )
      ]),
    );
  }
}
